#define _GNU_SOURCE
#include <assert.h>
#include <stdlib.h>
#include <string.h>

#include "cover.h"

struct cover_s {
	CoverType type;
    char * url_big;
    char * url_thumb;
};


/* Creates a cover with the given type */
cover_t cover_create (CoverType type) {
	cover_t new_cover = calloc (1,sizeof (struct cover_s));
	assert (new_cover != NULL);
	
	new_cover->type = type;
	new_cover->url_big = NULL;
	new_cover->url_thumb = NULL;

	return new_cover;
}

/* Free it's memory*/
cover_t cover_destroy (cover_t cover) {
	assert (cover != NULL);
	
	if (cover->url_big != NULL)
		free (cover->url_big);

	if (cover->url_thumb != NULL)
		free (cover->url_thumb);

	free (cover);
	return NULL;
}

/* Adds the url of the big picture of the cover*/
void cover_set_big (cover_t cover, char * url) {
	assert (cover != NULL);
	assert (url != NULL);
	assert (cover->url_big == NULL);

	cover->url_big = strdup (url);

	return;
}

/* Adds the url of the thumb picture of the cover */
void cover_set_thumb (cover_t cover, char * url) {
	assert (cover != NULL);
	assert (url != NULL);
	assert (cover->url_thumb == NULL);

	cover->url_thumb = strdup (url);

	return;
}

CoverType cover_type (cover_t cover) {
	return cover->type;
}
/* Gets the cover type */

/* Gets the url of the big picture of the cover*/
const char * cover_get_big (cover_t cover) {
	assert (cover != NULL);

	return cover->url_big;
}

/* Gets the url of the thumb picture of the cover */
const char * cover_get_thumb (cover_t cover) {
	assert (cover != NULL);

	return cover->url_thumb;
}

